package com.quick.serivce.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quick.mapper.SynTagsMapper;
import com.quick.serivce.ISynTagsService;
import com.quick.wx.pojo.SynTags;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SynTagsServiceImpl implements ISynTagsService {

    @Autowired
    private SynTagsMapper synTagsMapper;

    @Override
    public List<SynTags> selectAll(String type) {
        QueryWrapper<SynTags> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SynTags::getState,"00");
        queryWrapper.lambda().eq(SynTags::getType, type);
        List<SynTags> list = synTagsMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public void updateState(String state,String openId,Boolean subscribe) {
        QueryWrapper<SynTags> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SynTags::getOpenId,openId);
        List<SynTags> list = synTagsMapper.selectList(queryWrapper);
        if(CollectionUtils.isNotEmpty(list)){
            for(SynTags synTags:list){
                synTags.setState(state);
                synTags.setSubscribe(subscribe);
                synTagsMapper.updateById(synTags);
            }
        }
    }
}
